<template>
    <el-dialog v-model="visible" title="编辑标签" width="60%" align-center >
            <el-form  :model="examlabel" label-width="80px">
        <el-form-item label="标签名">
        <el-input v-model="examlabel.labelname" placeholder="请输入标签名" />
        </el-form-item>

    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="close">返回</el-button>
        <el-button type="primary" @click="saveLabel">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import {ref,reactive,watch,onMounted,defineEmits} from 'vue'
import userApi from '@/api/exam/examlabel.js'
const emit = defineEmits(['editVisible'])
let props=defineProps({
    visibleModel:{
        type:Boolean,
        default:false
    },
    id:{
        type:Number,
        default:0
    }
 })
 let visible=ref(props.visibleModel);
 watch(visible,(newVal) => {
      console.log(newVal);
      emit('editVisible');
    }
   )
 let examlabel=ref({
    id:"",
    labelname:"",
   
   });
   onMounted(()=>{
    userApi.getOne(props.id).then(response=>{
      console.log(response);
      examlabel.value.id=response.data.data.id;
      examlabel.value.username=response.data.data.labelname;
    })
   })
  const saveLabel=()=>{
     console.log(examlabel);
     userApi.updateExamLabel(examlabel.value).then(response=>{
      console.log(response);
      if(response.data.code==20000){
        visible.value=false;
        location.reload(true);
      }
    })
   }
   const close=()=>{
    //props.visibleModel.value=false;
    visible.value=false;
    console.log( props.visibleModel);
   }
</script>
<style scoped>

</style>
